const basePath2="http://localhost:8080/eshop_java"

$(document).ready(function () {
    initPage()//页面初始化
    //其他初始化
});
function initPage() {
    $(".header").load("/html/common/header.html")
    $(".menu").load("/html/common/menu.html")
    $(".footer").load("/html/common/footer.html")
}


//获得地址览的参数值
function getUrlString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");

    var r = decodeURI(window.location.search).substr(1).match(reg);

    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}

/**
 *去 购 物 车
 */
function goShopCar() {
    let obj=new Object();
    obj.m="list";
    $.ajax({
        async:true,
        // Ajax请求设置xhrFields的withCredentials为true实现跨域访问
        xhrFields: {
            withCredentials: true
        },
        type:"POST",
        url:basePath2+"/api/auth/shopCar",
        dataType:"json",
        data:obj,
        success:function (result) {
            console.log(result);
            if(result.code==505||result.code==506){
                //跳转到登录页面
                location.href="/html/notLoginView.html";
            }else if(result.code==200){
                location.href="/html/shopCarList.html"
            }
        },
        error:function (e) {
            console.log(e.status);
            console.log(e.responseText);
        }
    });

}

/**
 * d点击订单列表处理
 */
function goOrderList() {
    let obj=new Object();
    obj.m="list";
    $.ajax({
        async:true,
        // Ajax请求设置xhrFields的withCredentials为true实现跨域访问
        xhrFields: {
            withCredentials: true
        },
        type:"POST",
        url:basePath2+"/api/auth/orders",
        dataType:"json",
        data:obj,
        success:function (result) {
            console.log(result);
            if(result.code==505||result.code==506){
                //跳转到登录页面
                location.href="/html/notLoginView.html";
            }else if(result.code==200){
                location.href="/html/orderList.html"
            }
        },
        error:function (e) {
            console.log(e.status);
            console.log(e.responseText);
        }
    });

}